package ModelLayer;
import java.util.Calendar;
import java.text.SimpleDateFormat;

/**
 * Write a description of class Loan here.
 * 
 * @author (Group1:Georgi,Roland and Mindaugas) 
 * @version (a version number or a date)
 */
public class Loan
{
    private long id;
    private int period;
    private String borrowDate;
    private String state;
    private Person person;
    private Copy copy;
    
    /**
     * Constructor of Class Loan
     */
    public Loan(long id, String borrowDate, int period, String state,  Person person,Copy copy)
    {
        this.id=id;
        this.borrowDate=borrowDate;
        this.period=period;
        this.state=state;
        this.person=person;
        this.copy=copy;       
    }
    
     public Loan(long id,int period,Person person,Copy copy)
    {
        this.period=period;
        this.id=id;
        this.person=person;
        this.copy=copy;
        borrowDate=getTodaysDate();
        state="In time";
    }
    /**
     * Changes the State to late Status.
     */
    public void stateReturnedLate()
    {
      state="Returned too late,charge required!";
    }
    
    /**
     * Updates the state according to the days.
     */
    public void updateStateAccordingDays(int days)
    {
        if(days>period)
          stateReturnedLate();
    
    }
    
    /**
     * Gets the Date from the system at the time when the loan was made.
     */
    public String getTodaysDate()
    {
       Calendar currentDate = Calendar.getInstance();
       SimpleDateFormat formatter=  new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss");
       String dateNow = formatter.format(currentDate.getTime());
       return dateNow;
    }
    
    // Accesor Methods
    public long getID()
    {
        return id;
    }
    
    public int getPeriod()
    {
        return period;
    }
    
    public String getBorrowDate()
    {
        return borrowDate;
    }
    
    public String getState()
    {
        return state;
    }
    
    public Person getPerson()
    {
        return person;
    }
    
    public Copy getCopy()
    {
        return copy;
    }
    
    //Mutator Methods
    public void setID(long id)
    {
        this.id=id;
    }
    
    public void setPeriod(int period)
    {
        this.period=period;
    }
    
    public void setBorrowDate(String borrowDate)
    {
        this.borrowDate=borrowDate;
    }
    
    public void setState(String state)
    {
        this.state=state;
    }
    
    public void setPerson(Person person)
    {
        this.person=person;
    }
    
    public void setCopy(Copy copy)
    {
        this.copy=copy;
    }
    
    
   
}
